package net.oschina.git.haxteam.zrank.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class dbManager {


	public static void loadUserName(String username){
		ConnectionManager mysqldatabase = ConnectionManager.getInstance();
		Connection connection = null;
		PreparedStatement ps = null;
		// 创建表
		try {
			connection = mysqldatabase.getHikariDataSource().getConnection();
			ps = connection.prepareStatement("create table if not exists " + "Zrank" + " (id int auto_increment primary key, `PlayerName` varchar(50), `Level` varchar(10), `Xp` varchar(100), `Achievement` varchar(40), `Achievementpoint` varchar(40), `Money` varchar(40))default charset=utf8;");
			ps.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				connection.close();
			} catch (SQLException e) {
				// TODO

				e.printStackTrace();
			}
		}
	}


	public static void InitializationTable(){
		ConnectionManager mysqldatabase = ConnectionManager.getInstance();
		Connection connection = null;
		PreparedStatement ps = null;
		// 创建表
		try {
			System.out.println("[等级&成就]正在初始化用户数据库...");
			connection = mysqldatabase.getHikariDataSource().getConnection();
			ps = connection.prepareStatement("create table if not exists " + "Zrank" + " (id int auto_increment primary key, `PlayerName` varchar(50), `Level` varchar(10), `Xp` varchar(100), `Achievement` varchar(40), `Achievementpoint` varchar(40), `Money` varchar(40))default charset=utf8;");
			ps.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				System.out.println("[等级&成就]数据库初始化完成.");
				connection.close();
			} catch (SQLException e) {
				// TODO
				e.printStackTrace();
				System.out.println("[等级&成就]请检查数据库是否正确连接.");
			}
		}
	}
}
